---
title: Validate PDF bytes
summary: Guards that a byte array is a valid PDF before further processing.
status: draft
owner: SAIF Doc Gen
last_reviewed: 2026-09-17
library: PdfAPI.Core
reference_type: package
operation_id: OP-01
trigger: PdfClientService.ValidatePdf(byte[], string) invoked
---

# Validate PDF bytes

This operation is the common guard used by every other `PdfClientService` operation: it tests whether a byte array carries a PDF signature and aborts with a domain exception if it does not.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-01 |
| **Trigger** | Caller invokes `ValidatePdf(byte[] file, string fileName = null)` |
| **Inputs** | PDF bytes, optional file name |
| **Outputs** | Returns without a value on success; throws `PdfException` on failure |
| **Primary components** | `PdfAPI.Core.PdfClientService.ValidatePdf(byte[], string)` |
| **Entry point** | `PdfAPI.Core\Services\PdfClientService.cs` |

## Steps

1. Call `IsPdf(file)` to test the byte array for a PDF signature. ([BR-01](../business-rules.md#br-01-pdf-signature-validation), [BR-02](../business-rules.md#br-02-null-bytes-are-never-a-pdf))
2. If not a PDF, compose a message including the file name when one was supplied and throw `PdfException`. ([BR-03](../business-rules.md#br-03-invalid-pdf-input-aborts-with-pdfexception))
   - On failure: throws `PdfException("ValidatePdf: The file '<name>' is not a valid pdf document.")`
3. If valid, return without a value.

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start(["ValidatePdf(bytes, fileName)"]) --> Check["IsPdf(bytes)"]
	Check -->|false| Err([Throw PdfException])
	Check -->|true| Ok([Return])
```

## Failure and edge-case behavior
- A null byte array is never a valid PDF and always triggers the throw path ([BR-02](../business-rules.md#br-02-null-bytes-are-never-a-pdf)).
- When no file name is supplied, the exception message omits the file name segment.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)
- [Security and authorization](../security-authorization.md)

## Sources
- `PdfAPI.Core\Services\PdfClientService.cs`
